from text_litemall.api.base_app_api import BaseApi


class ProductApi(BaseApi):


    def search(self):
        info = {
            "method": "GET",
            "url": f"{self.base_url}wx/goods/list?keyword=火焰杯测试商品",
            "headers": {'X-Litemall-Admin-Token': self.token},
        }
        r = self.request(**info)

        self.goodsId = r.json()['data']['list'][0]['id']
        return self.goodsId

    def get(self):
        info = {
            "method": "GET",
            "url": f"{self.base_url}wx/goods/detail?id={self.goodsId}",
            "headers": {'X-Litemall-Admin-Token': self.token},
        }
        r = self.request(**info)
        self.productId = r.json()['data']['productList'][0]['id']
        return self.productId

    def add(self):

        print(self.goodsId,self.productId)
        info = {
            "method": "POST",
            "url": f"{self.base_url}wx/cart/add",
            "headers": {'x-litemall-token': self.token},
            "json": {"goodsId": self.goodsId, "number": 1, "productId": self.productId}
        }
        r = self.request(**info)
        return r.json()


    def delete(self):
        info = {
            "method": "POST",
            "url": f"{self.base_url}wx/cart/delete",
            "headers": {'x-litemall-token': self.token},
            "json": {"productIds":[self.productId]}
        }
        r = self.request(**info)
        return r.json()

